(function ($app) {
    $app.module('gtPartyApp').controller('mh_linkListCtrl', function ($scope, $http, $modal, $ocLazyLoad, $alert, $loading, $state, $bsRouterState, AuthUser, $timeout, $excel) {
        $state.params = $bsRouterState.$params($scope);
        $scope.isShow = false;
        $scope.moreTxt = "更多";
        $scope.loginUserId = AuthUser.getUser().Id;
        //定义数据集合
        $scope.dataList = []; //列表数据
        //查询条件
        $scope.selectparams = {
            pageindex: 1,
            pagesize: 10,
            title: ''
        };
        $scope.pageInfo = {ptotal: 0};
        //定义模态框
        mhLink_editCtrl.$inject = ['$scope', '$http', '$alert', '$loading'];
        mhLink_editModal = $modal({
            resolve: {
                load: ['$ocLazyLoad', function ($ocLazyLoad) {
                }]
            },
            scope: $scope,
            controller: mhLink_editCtrl,
            templateUrl: '../main/mh/link/edit.html',
            show: false,
            animation: 'am-fade-and-slide-top'
        });

        //加载列表数据
        $scope.getList = function () {
            $http
            ({
                method: 'get', url: '../../api/mh/getLinkList', params: $scope.selectparams
            }).then(function (result) {
                $scope.dataList = result.data.item.list;
                $scope.pageInfo.ptotal = result.data.item.total;
            }, function (res) {
                $scope.showMsg('错误', '服务器错误');
            });
        };

        $scope.search = function () {
            $scope.getList();
        };

        $scope.edit = function (id) {
            mhLink_editModal.params = {
                id: id,
                title: id ? "修改链接" : "新增链接"
            };
            mhLink_editModal.parentLoad = $scope.getList;
            mhLink_editModal.$promise.then(mhLink_editModal.show);
        };

        $scope.delete = function (id) {
            if (confirm("是否确定删除？")) {
                $http({
                    url: "../../api/mh/deleteLink",
                    method: 'GET',
                    params: {id: id}
                }).then(function (result) {
                    $scope.showMsg("消息", result.data.msg);
                    if (result.data.success) {
                        $scope.getList();
                    }
                });
            }
        };

        $scope.$watch("selectparams.pageindex", function (newVal, oldVal) {
            if ($scope.pageInfo.ptotal > 0) {
                $scope.getList();
            }
        });

        $scope.getList();

    });
})(angular);